home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / zindent7.zip / ZINKEYTP.INC < prev    next >
Text File  |  1987-03-30  |  7KB  |  260 lines

  1. (****************************************************************)
  2. (* Include File                                                 *)
  3. (* KeyWord Turbo Pascal  v. 0600pm, wed, 25.Mar.87, Glen Ellis  *)
  4. (****************************************************************)
  5.  
  6. (* called by :
  7. (*             pKEYTP( SOLL, SIP, SIN, SLM, SMW, SEB,SLB
  8. (*
  9. (*  parameters sent:
  10. (*
  11. (*   (SysOutLine, SysIndentPos, SysIndentNum , SysLenMax, SysMarkWrite );
  12. (*    SOLL        SIP           SIN            SLM        SMW
  13. (*
  14. (*   System Enable Begin flag
  15. (*   SEB
  16. (*
  17. (*   Begin/End counter :
  18. (*     SLB
  19. (*
  20. (*   procedure pINDENT() is located in ZinSTR.inc
  21. (*
  22. (* *)
  23.  
  24. (*---------------------------------------------------------------------------*)
  25. procedure pKEYTP( var KLine : THEstr ; var KIPos : nbr ; KINum , KLenMax : nbr;
  26.   var KMwrite, KEB : lgc ; var KLB : nbr);
  27.  
  28.   (* also, uses SysComment
  29.   (*
  30.   (* requires STRING.INC library of string functions
  31.   (* all are var in order to allow sending back altered values
  32.   (* kLINE  := OutLine
  33.   (* kIPOS := indentpos = current indent position
  34.   (* kINUM := indentnum = length of indent group
  35.   (* KMwrite := KMwrite = controls write to disk
  36.   (* *)
  37.  
  38.   var
  39.        (* local memvars *)
  40.        trimcnt : nbr;
  41.        leftmgn  : nbr;
  42.        wkLINE : THEstr;
  43.        KMark : lgc;
  44.        x,y,z   : nbr;
  45.  
  46.        PosHead : lgc;
  47.        PosBegin, PosCase, PosRepeat, PosRecord : nbr;
  48.        PosEnd  : nbr;
  49.  
  50. (*========================================================*)
  51.  
  52. begin  (* Proc *)
  53.    
  54.    trimcnt := 0;
  55.    leftmgn := 0;
  56.    
  57.    (*--- Trim Right Spaces,  We Will Not Pad-Right. *)
  58.    (*--- Trim Left Spaces, Count Them, Prep for Margin adjusted Pad-Left *)
  59.    pTrimLCntR(kLINE,trimcnt);(**)
  60.    (* trimcnt used by KEB controller *)
  61.    
  62.    (*--- Vertical Blank Filler *)
  63.    IF (SysVertiate)
  64.       and (length(kLine) = 0)
  65.       and (KEB)
  66.       then kLine := '(**)';
  67.    (*
  68.    (* this filler group looks cluttered,
  69.    (* and was selected as a compromise,
  70.    (* because Pascal does not tolerate the semi-colon
  71.    (* as a vertical filler between functions and procedures !
  72.    (* *)
  73.    
  74.    (*--- Create Working Line *)
  75.    wkLINE := kLINE;
  76.    
  77.    (*--- Init *)
  78.    KMark := false;
  79.    KMwrite := true;
  80.    
  81.    (*--- convert working line to all caps *)
  82.    (* pAllCaps(wkLINE); (**)
  83.    pUpCaseFirst(wKLine); (**)
  84.    
  85.    
  86.    (*--- check for pos() of pKEYWORDs *)
  87.    
  88.  
  89.    (* optional function.
  90.    (*---------------------------------------------------
  91.    (* detect first occurence of 'begin', then set flag
  92.    (* this delaying tactic protects the title/header area.
  93.    (**)
  94.    
  95.    IF not KEB   (* not started YET ! *)
  96.    then
  97.    begin
  98.       IF (pos('BEGIN',wkLINE)=1)  (* time to Start , NOW ! *)
  99.       then
  100.       begin
  101.          TrimCnt := 0;
  102.          KEB := true; (* start normal indent now ! *)
  103.          (*   will not pass  through here again ! *)
  104.       end;
  105.       (* hold on to the current trim left margin counter *)
  106.       KIPOS := trimcnt;
  107.    end;
  108.    
  109.    
  110.    (*-------------- Key Enable Begin --------------------*)
  111.    IF KEB then  (*  then enable line parse routines *)
  112.    begin
  113.  
  114.       (*---------*)
  115.       (* Comment *)
  116.  
  117.       IF ( pos('{',wkLINE) = 1 )
  118.          or ( pos('(*',wkLINE) = 1 )
  119.          or ( pos(';',wkLINE) = 1 )
  120.          or (length(wkLINE)=0)
  121.       then
  122.       begin
  123.          IF SysComment
  124.             then pINDENT(kLINE,kIPOS,kLenMax)
  125.          ELSE KMwrite := false;
  126.          KMark := true;
  127.       end;
  128.  
  129.  
  130.       (*-------< Allow following module to detect keywords >-------*)
  131.  
  132.       (* I forgot to parse for 'RECORD' right through version #5 ! *)
  133.       (* Thanks to David Beard, Memphis, Tn, a REAL Programmer ! *)
  134.  
  135.       (*------------------------------------------------*)
  136.       (* handle  BEGIN / CASE / REPEAT / RECORD  head.  *)
  137.  
  138.       PosBegin  := pos('BEGIN',  wkLINE);
  139.       PosCase   := pos('CASE',   wkLINE);
  140.       PosRepeat := pos('REPEAT', wkLINE);
  141.       PosRecord := pos('RECORD', wkLINE);
  142.  
  143.       PosHead := false;
  144.  
  145.       IF
  146.       (
  147.       (posBEGIN=1)
  148.       and
  149.       ( (pos('BEGIN ',wkLINE)=1) or (length(wkLINE) = PosBEGIN + 4) )
  150.       )
  151.          then PosHead := true;
  152.  
  153.       IF
  154.       (
  155.       (posCASE=1)
  156.       and
  157.       ( (pos('CASE ',wkLINE)=1) or (length(wkLINE) = PosCASE + 3) )
  158.       )
  159.          then PosHead := true;
  160.  
  161.       IF
  162.       (
  163.       (posREPEAT=1)
  164.       and
  165.       ( (pos('REPEAT ',wkLINE)=1) or (length(wkLINE) = PosREPEAT + 5) )
  166.       )
  167.          then PosHead := true;
  168.  
  169.       IF
  170.       (
  171.       (posRECORD=1)
  172.       and
  173.       ( (pos('RECORD ',wkLINE)=1) or (length(wkLINE) = PosRECORD + 5) )
  174.       )
  175.          then PosHead := true;
  176.  
  177.       IF PosHead then
  178.       begin
  179.          pINDENT(kLINE,kIPOS,kLenMax);
  180.          kIPOS := kIPOS + kINUM;
  181.          KLB := KLB + 1; (* Begin/End counter *)
  182.          KMark := true;
  183.          KEB := true;
  184.       end;
  185.  
  186.  
  187.  
  188.       (*------------------*)
  189.       (* handle 'IF' tail.*)
  190.  
  191.       IF (pos('THEN ',wkLINE)=1)
  192.          or (pos('DO ' ,wkLine)=1)
  193.          or (pos('AND ',wkLine)=1)
  194.          or (pos('OR ' ,wkLine)=1)
  195.          then  (* temporary Offset *)
  196.       begin
  197.          kIPOS := kIPOS + kINUM;
  198.          pINDENT(kLINE,kIPOS,kLenMax);
  199.          kIPOS := kIPOS - kINUM;
  200.          KMark := true;
  201.       end;
  202.  
  203.  
  204.       (*-------------------------------------*)
  205.       (* handle 'BEGIN' 'CASE' 'RECORD' tail.*)
  206.  
  207.       PosEnd := pos('END',wkLINE);
  208.  
  209.       IF ( PosEnd = 1 )
  210.       and
  211.       (
  212.       (pos('END ;',wkLINE) = 1)
  213.       or
  214.       (pos('END;',wkLINE) = 1)
  215.       or
  216.       (length(wkLINE) = PosEnd + 2)
  217.       )
  218.       then
  219.       begin
  220.          (* KEY line *)
  221.          kIPOS := kIPOS - kINUM; (* Position *)
  222.          pINDENT(kLINE,kIPOS,kLenMax);
  223.          KLB := KLB -1; (* Begin/End counter *)
  224.          KMark := true;
  225.       end;
  226.  
  227.  
  228.       (*----------------------------------------------*)
  229.       (* handle 'REPEAT' tail *)
  230.  
  231.       IF  (pos('UNTIL ',wkLINE)=1)
  232.       then
  233.       begin
  234.          (* KEY line *)
  235.          kIPOS := kIPOS - kINUM; (* Position *)
  236.          pINDENT(kLINE,kIPOS,kLenMax);
  237.          KLB := KLB -1; (* Begin/End counter *)
  238.          KMark := true;
  239.       end;
  240.  
  241.    end; (* KEB *)
  242.    (* bottom of IF 'Key Enable Begin' KEB *)
  243.  
  244.  
  245.    (*-----------------*)
  246.    (*  NONE of ABOVE  *)
  247.  
  248.    IF not(KMark) then
  249.    begin
  250.       IF (pos('(*>*)',wkLine)=1) (* margin move right *)
  251.          then  kIPOS := kIPOS + kINUM;
  252.       (*     normal common line       *)
  253.       (* left pad current kIPOS count *)
  254.       pINDENT(kLINE,kIPOS,kLenMax);
  255.    end;
  256.  
  257. end; (* Proc *)
  258.  
  259. (********************************************************************)
  260. (*<<<>>>*)